<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class usersadmin extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function __construct() {
		parent::__construct();
		ini_set('session.cookie_httponly',1); 
		ini_set('session.use_only_cookies',1);
		$this->load->model('useradmin_class');
	}
	public function list_usersadmin(){
		$data=array();
		$post = $this->input->post();
		$userInfo = $this->useradmin_class->list_usersadmin_data($post);
		if($userInfo!=0){
			foreach($userInfo as $key=>$value){
				$data['intID'][$key]=$value['intID'];			
				$data['strName'][$key]=$value['strName'];
				$data['dateBirthday'][$key]=$value['dateBirthday'];
				$data['intAge'][$key]=$value['intAge'];
				$data['strEmail'][$key]=$value['strEmail'];
				$data['strImgLink'][$key]=$value['strImgLink'];
			}
		}
		echo json_encode($data);
	}
	public function get_useradmin_data(){
		$post = $this->input->post();
		$userInfo = $this->useradmin_class->get_useradmin_data($post);
		if($userInfo != 0){
			$data['intID'] = $userInfo['intID'];
			$data['strName'] = $userInfo['strName'];
			$data['dateBirthday'] = $userInfo['dateBirthday'];
			$data['strEmail'] = $userInfo['strEmail'];
			$data['strImgLink'] = $userInfo['strImgLink'];
		}
		echo json_encode($data);
	}
	public function save_usersadmin(){
		$post = $this->input->post();
		$message = '';
		$users = $this->useradmin_class->get_useradmin_data($post);
		
		if($users!=0){
			$message = $this->useradmin_class->update($post);
		} else {
			$message = $this->useradmin_class->add_useradmin($post);
		}
		echo json_encode($message);
	}
	public function add_useradmin(){
		$post = $this->input->post();
		$userInfo = $this->useradmin_class->add_useradmin($post);
		echo json_encode($userInfo);
	}	
	public function change_perm_useradmin(){
		$post = $this->input->post();
		$userInfo = $this->useradmin_class->change_permadmin($post);
		echo json_encode($userInfo);
	}	
	public function delete_useradmin(){
		$post = $this->input->post();
		$userInfo = $this->useradmin_class->delete($post);
		echo json_encode($userInfo);
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */